<template>
  <div class="content-box">
    <nav-title title="语言能力" />
    <edit-option-line label="语言" :important="true" :vals="lanList" v-model="language.rsLangCd"></edit-option-line>
    <edit-line label="证书名称" v-model="language.cDescr"></edit-line>
    <edit-date-line label="获得日期" v-model="language.cDate"></edit-date-line>
    <edit-line label="考试分数" type="number" v-model="language.cScore"></edit-line>
    <edit-option-line label="熟练度"  :important="true" :vals="techList" v-model="language.cLangLv"></edit-option-line>
   
    <div class="btn_region">
      <div class="submit-btn" @click="save">保存</div>
      <div class="remove-btn" @click="remove"> 删除 </div>
    </div>
    <div stype="width:100%;height:30px">&nbsp;</div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import CommonUtil from '../../../../components/basic/util'
import EditLine from '../../../../components/basic/EditLine'
import EditDateLine from '../../../../components/basic/EditDateLine'
import EditOptionLine from '../../../../components/basic/EditOptionLine'
import { saveLan,delLan,getDicItem } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
     EditOptionLine, EditDateLine, EditLine
  },
  mounted(){
    //获取字典
  
    CommonUtil.loadDic(this.lanList, 'RS_LANG_CD', "xlatshortname","fieldvalue");//语言字典
    CommonUtil.loadDic(this.techList, 'C_LANG_LV', "xlatshortname","fieldvalue");//学历字典
    if(this.$store.state.hid){
      this.language.rsHireId = this.$store.state.hid
      this.langDel.rsHireId = this.$store.state.hid
    }
  },
  data() {
    return {
      language: {
        rsHireId: '',
      },
      langDel: {
        rsHireId: '',
        cSeqno: ''
      },

      lanList: [],
      techList: [],
    }
  },
  created() {
    this.getLang()
  },
  
  methods: {
    save() {

      const that = this
      console.log(that.language)
      if(!CommonUtil.valid(this, this.language,"rsLangCd","请选择语言") 
        || !CommonUtil.valid(this, this.language,"cLangLv","请选择熟练度") 
        ){
        return;
      }

      saveLan(json2Form(that.language)).then(res => {
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })


    },
    remove() {

      const _this = this;
      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delLan(json2Form(_this.langDel)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                  _this.$router.push('/informationCollection/userInfo');
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '提示',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })


          }
        })
    },
    getLang() {
      if(this.$route.params.lang){
        this.language = this.$route.params.lang
        this.langDel.cSeqno = this.$route.params.lang.cSeqno
        console.log(this.language)
      }
      CommonUtil.fillDateEmpty(this.language, ['cDate'])
    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
</style>
